/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.starter.iam.authentication.local.user.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.snail.starter.commons.error.CommonErrorCode;
import com.snail.starter.commons.exception.BizException;
import com.snail.starter.db.enums.EnableOrDisEnableEnum;
import com.snail.starter.iam.authentication.local.user.entity.LocalUser;
import com.snail.starter.iam.authentication.local.user.mapper.LocalUserMapper;
import org.springframework.stereotype.Service;

/**
 * @author zgadmin
 * @date 2025/8/26 19:05
 */
@Service
public class LocalUserService extends ServiceImpl<LocalUserMapper, LocalUser> {

    public LocalUser checkUser(Long tenantId, Long accountId) {
        LocalUser localUser = getOne(Wrappers.lambdaQuery(LocalUser.class).eq(LocalUser::getTenantId, tenantId).eq(LocalUser::getAccountId, accountId));
        if (null == localUser) {
            throw BizException.of(CommonErrorCode.USER_NOT_EXISTS);
        }
        if (!EnableOrDisEnableEnum.ENABLE.equals(localUser.getStatus())) {
            throw BizException.of(CommonErrorCode.USER_DISABLE);
        }
        return localUser;
    }

}